package fr.upmc.mdoc.tp1.domain;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import fr.upmc.mdoc.tp1.models.PhoneNumber;
import fr.upmc.mdoc.tp1.tools.HibernateUtil;

public class DAOPhoneNumber {

	private Session session = null;
	private Transaction tx = null;

	public DAOPhoneNumber() {
		session = HibernateUtil.getSessionFactory().openSession();
	}

	@SuppressWarnings("unchecked")
	public List<PhoneNumber> getPhones(int idContact) {

		tx = session.beginTransaction();

		List<PhoneNumber> phones = (List<PhoneNumber>) session.createQuery(
				"from PhoneNumber p" + "where p.contact.contactId='"
						+ idContact + "'").list();

		tx.commit();

		return phones;
	}
}
